//
//  PzNorPhotoSearchView.swift
//  Pz
//
//  Created by 蓝鳍互娱 on 2024/7/4.
//

import Foundation
class PzNorPhotoSearchView: UIView {
    var norPhotoSearchBlock: ((_ searchText:String?) -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        creatSubView()
    }
    lazy var photoSearchField: UITextField = {
        let field = UITextField()
        field.textColor = UIColor(hex: 0x62546B)
        field.font = UIFont.systemFont(ofSize: 24.fitScale(), weight: .regular)
        field.layer.borderColor = UIColor(hex: 0xFFFFFF,transparency: 0.2)?.cgColor
        field.layer.borderWidth = 1;
        field.layer.cornerRadius = 8.fitScale()
        field.clipsToBounds = true
        field.placeholder = "请输入名称"
        field.delegate = self
        field.returnKeyType = UIReturnKeyType.search
        field.setValue(NSNumber(value: 23.fitScale()), forKey: "paddingLeft")
        return field
    }()
    lazy var photoSearchImgView: UIImageView = {
        let imgView = UIImageView()
        imgView.image = UIImage(named: "pz_photoSearch")
        return imgView
    }()
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func creatSubView() {
        self.addSubview(photoSearchField)
        self.addSubview(photoSearchImgView)
        photoSearchField.snp.makeConstraints { make in
            make.edges.equalTo(0.fitScale())
        }
        photoSearchImgView.snp.makeConstraints { make in
            make.centerY.equalTo(photoSearchField)
            make.right.equalTo(0.fitScale())
            make.width.equalTo(0.fitScale())
            make.height.equalTo(0.fitScale())
        }
    }
}
extension PzNorPhotoSearchView:UITextFieldDelegate{
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        norPhotoSearchBlock?(photoSearchField.text)
        return true
    }
}
